#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#define INF 1000000000
#define MAXN 100000
#define MAXM 100005
#define s(T) scanf("%d", &T)
using namespace std;

struct RMQ{
    vector<int> blocks;
    vector<int> arr;
    int N;
    int rootN;
    int numblocks;

    void init(int n){
        N = n;
        rootN = (int)sqrt(N);
        numblocks = (N+rootN-1)/rootN;
        blocks.resize(numblocks);
        arr.resize(N);
    }

    void update(int idx, int val){
        arr[idx] = val;
    }

    void calc(){
        for (int i=0;i<numblocks;i++){
            int val = INF;
            for (int j=i*rootN;j<min(N,(i+1)*rootN);j++)
                val = min(val, arr[j]);
            blocks[i] = val;
        }
    }

    int query(int L, int R){
        if (L > R) return INF;
        int lblock = L/rootN, rblock = R/rootN;
        int val = INF;
        if (lblock == rblock){
            for (int i=L;i<=R;i++)
                val = min(val, arr[i]);
        } else {
            for (int i=L;i<(lblock+1)*rootN;i++)
                val = min(val, arr[i]);
            for (int i=lblock+1;i<rblock;i++)
                val = min(val, blocks[i]);
            for (int i=rblock*rootN;i<=R;i++)
                val = min(val, arr[i]);
        }
        return val;
    }
};

RMQ minq, maxq;
int N, Q;
vector<int> B;
int L, R;

int max(int a, int b){ return a>b?a:b; }

void input(){
    s(N);
    for (int i=0;i<N;i++){
        int x; s(x);
        B.push_back(x);
    }
}

void solve(){
    minq.init(N);
    maxq.init(N);

    for (int i=0;i<N;i++){
        minq.update(i, B[i]);
        maxq.update(i,-B[i]);
    }
    minq.calc();
    maxq.calc();

    s(Q);
    for (int i=0;i<Q;i++){
        s(L); s(R);
        int t = minq.query(L, R);
        int t1 = -maxq.query(0, L-1);
        int t2 = -maxq.query(L, R);
        int t3 = -maxq.query(R+1, N-1);
        cout << t << " " << t1 << " " << t2 << " " << t3 << endl;

        double ans = t+max(t1/1.0, max((t2-t)/2.0, t3/1.0));
        printf("%.1lf\n", ans+0.01);
    }
}

int main()
{
    freopen("MSTICK.txt","r", stdin);
    input();
    solve();
    return 0;
}
